//
//  UIBarButtonItem+Extension.swift
//  swiftWeibo
//
//  Created by 马雪山 on 2017/7/23.
//  Copyright © 2017年 xueshanma. All rights reserved.
//

import UIKit


extension UIBarButtonItem {
    
    //创建 UIBarButtonItem
    //遍历构造函数(简化空间创建,封装构造方法)
    //isBack 是否是返回按钮,如果是,加上箭头
    
    convenience init(title: String,fontSize:CGFloat = 16 ,target:AnyObject, action:Selector, isBack:Bool = false) {
        let btn = UIButton.init(frame: CGRect(x: 0, y: 0, width: 50, height: 40))
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationButtonReturn"
            btn.setImage(UIImage.init(named: imageName), for: .normal)
            btn.setImage(UIImage.init(named: imageName + "Click"), for: .highlighted)
        }
        
        //self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
    
}
